Skip to content

PHPORM-171 Set timestamps when using createOrFirst #2905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2024

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Apr 23, 2024

Fix PHPORM-171
Issue reported by @nicohell #2720 (comment)

Checklist

  • Add tests and ensure they pass
  • Add an entry to the CHANGELOG.md file
  • Update documentation for new features

@GromNaN GromNaN requested a review from a team as a code owner April 23, 2024 20:22
@GromNaN GromNaN requested a review from jmikola April 23, 2024 20:22
@GromNaN GromNaN changed the title PHPORM-171 Set timestamps when using createOrFirst PHPORM-171 Set timestamps when using createOrFirst Apr 23, 2024
Comment on lines +207 to +211

/* @see \Illuminate\Database\Eloquent\Model::performInsert */
if ($instance->usesTimestamps()) {
$instance->updateTimestamps();
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$user1 = User::createOrFirst(['email' => '[email protected]']);

$this->assertSame('[email protected]', $user1->email);
$this->assertNull($user1->name);
$this->assertTrue($user1->wasRecentlyCreated);
$this->assertEquals($createdAt, $user1->created_at->getTimestamp());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this use a comparison to assert that the created_at and updated_at fields are greater than or equal to the previously calculated current time?

I don't see anything in the PR that would guarantee the entire test completes within a single timestamp.

Copy link
Member Author

@GromNaN GromNaN Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Carbon::setTestNow freezes the clock, so that the date point that is used to populate create_at is the one that is set.

@GromNaN GromNaN requested a review from jmikola April 24, 2024 16:29
@GromNaN GromNaN changed the base branch from 4.3 to 4.2 April 24, 2024 21:05
@GromNaN GromNaN merged commit da27552 into mongodb:4.2 Apr 25, 2024
23 checks passed
@GromNaN GromNaN deleted the PHPORM-171 branch April 25, 2024 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants